package com.dongdongshop.serviceimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbContentCategoryMapper;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.pojo.TbContentCategoryExample;
import com.dongdongshop.service.ContentCategoryService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
@org.springframework.stereotype.Service
public class ContentCategoryServiceImpl implements ContentCategoryService {
    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;
    //查询所有

    @Override
    public List<TbContentCategory> findall(String name) {
        try {
            TbContentCategoryExample tce = new TbContentCategoryExample();
            TbContentCategoryExample.Criteria criteria = tce.createCriteria();
            if (name != null && !"".equals(name)){
                criteria.andNameLike("%" + name + "%");
            }
            List<TbContentCategory> list = tbContentCategoryMapper.selectByExample(tce);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //增加
    @Override
    public Boolean insertcategory(TbContentCategory tbContentCategory) {
        int i = tbContentCategoryMapper.insertSelective(tbContentCategory);
        if (i>0){
            return true;
        }
        return false;
    }

    //删除
    @Override
    public Boolean deletecategory(Long[] ids) {
        try {
            for (int i = 0; i < ids.length; i++) {
                tbContentCategoryMapper.deleteByPrimaryKey(ids[i]);
            }
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }

    //回显
    @Override
    public TbContentCategory selectById(Long id) {
        TbContentCategory tbContentCategory = tbContentCategoryMapper.selectByPrimaryKey(id);
        return tbContentCategory;
    }

    //修改
    @Override
    public Boolean updateCategory(TbContentCategory tbContentCategory) {
        try {
            int i = tbContentCategoryMapper.updateByPrimaryKeySelective(tbContentCategory);
            if (i>0){
                return true;
            }
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
